﻿using Model;
using System;
using System.Collections.Generic;
using System.Text;
using HtmlAgilityPack;
namespace Hotfix
{
    public class Parser : IDataParser
    {
        HtmlDocument doc = new HtmlDocument();
        public OpenData Parse(string text)
        {
            doc.LoadHtml(text);
            OpenData openData = Get(PlayType.KL8);
            return openData;
        }

        public OpenData Get(PlayType type)
        {

            HtmlNode htmlNode = doc.DocumentNode.SelectSingleNode("//*[@id=\"game_notice\"]/div[5]");

            HtmlNode issueNode = htmlNode.SelectSingleNode("div[2]/span");

            // 获取期数号码
            HtmlNodeCollection srcCodeNode = htmlNode.SelectNodes("div[2]/div[2]/ul[1]/li");

            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < srcCodeNode.Count; i++)
            {
                builder.Append(srcCodeNode[i].InnerText);
                if (i != srcCodeNode.Count - 1)
                    builder.Append(",");
            }

            string issue = issueNode.InnerText;
            string srcCode = builder.ToString();
            return new OpenData { Issue = issue, SrcCode = srcCode, PlayType = type, OpenTime = DateTime.Now };
        }
    }
}